(function () {
    "use strict";



    var viewer = new Cesium.Viewer("cesiumContainer", {
        imageryProvider: new Cesium.TileMapServiceImageryProvider({
    url: Cesium.buildModuleUrl("http://49.232.25.27:8081/cesiumdemo/NaturalEarthII"),
  }),
        sceneMode: Cesium.SceneMode.SCENE3D,
        timeline: false,
        animation: false,
        geocoder:false,
        homeButton:false,
        sceneModePicker:false,
        //baseLayerPicker:false,
        navigationHelpButton:false,
        fullscreenButton:false,
        vrButton:false,
    });

    var longitude = 116.399669;
    var latitude = 39.935297;
    var height = -1.1406325468715177e-9;
    var heading = 0;
    var tileset = new Cesium.Cesium3DTileset({
        url: 'http://49.232.25.27:8081/cesiumdemo/output3d/tileset.json'
    });

const imageryLayers = viewer.imageryLayers;
    viewer.scene.primitives.add(tileset);
/*
    tileset.readyPromise.then(function(argument) {
        var position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
        var mat = Cesium.Transforms.eastNorthUpToFixedFrame(position);
        var rotationX = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(heading)));
        Cesium.Matrix4.multiply(mat, rotationX, mat);
        tileset._root.transform = mat;
        viewer.camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height+200)});
    });
*/


/*
    tileset.readyPromise.then(function(argument) {
//viewRectangle
  const west = 116.147856;
  const south = 39.733175;
  const east = 116.761866;
  const north = 40.039669;

  const rectangle = Cesium.Rectangle.fromDegrees(
    west,
    south,
    east,
    north
  );
  viewer.camera.setView({
    destination: rectangle,
  });

 // Show the rectangle.  Not required; just for show.
          viewer.entities.add({
            rectangle: {
              coordinates: rectangle,
              fill: false,
              outline: true,
              outlineColor: Cesium.Color.WHITE,
            },
          });
})
*/


    tileset.readyPromise.then(function(argument) {
//flyToRectangle
  const west = 116.147856;
  const south = 39.733175;
  const east = 116.761866;
  const north = 40.039669;
  const rectangle = Cesium.Rectangle.fromDegrees(
    west,
    south,
    east,
    north
  );

  viewer.camera.flyTo({
    destination: rectangle,
  });


imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
            url: 'https://dev.virtualearth.net',
            mapStyle: 'Aerial',
            culture: 'zh-Hans',
            key: 'AlgsUaY9R3p9MHmp-GN-o4j9HsdPrxboqvpaWwL5Da5vwQv7YkdC426vW1s6Lxrk',
            rectangle : Cesium.Rectangle.fromDegrees(116.147856, 39.733175, 116.761866, 40.039669)
        })
);

 // Show the rectangle.  Not required; just for show.
          viewer.entities.add({
            rectangle: {
              coordinates: rectangle,
              fill: false,
              outline: true,
              outlineColor: Cesium.Color.WHITE,
            },
          });
})


}());